Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the only way to create an instance of an AI Service is to manually use the builder:
While this is pretty simple and flexible, this can be made even more simple and natural for the Spring Boot users.
With this change, any interface annotated with
@AiService
will be automatically registered as a bean and configured to use all the LangChain4j components (beans) available in the context (e.g. chat model, chat memory, tools, etc.).Here is an example of the simplest declarative AI Service:
langchain4j.open-ai.chat-model.api-key=${OPENAI_API_KEY}
By configuring this property, an instance of the
OpenAiChatModel
will be autoconfigured as a bean. (This is not new, it was already possible withlangchain4j-open-ai-spring-boot-starter
.)When the application starts, autoconfiguration in
langchain4j-spring-boot-starter
will scan the classes of the project (starting from the package where@SpringBootApplication
is located) and will find all interfaces annotated with@AiService
.It will use all available components (such as
OpenAiChatModel
in this case) when creating an instance of an AI Service.It is also possible to customize which components should be used for the particular AI Service: